Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Integrate new TokenListController polling pattern [Extension] #28198

Closed
wants to merge 65 commits into from

Conversation

gambinish
Copy link
Contributor

@gambinish gambinish commented Oct 31, 2024

Description

TokenListController is currently responsible for maintaining a list of all tokens per chain. This dataset is accessible via tokenList state variable in metamask state. After this task is complete, this token list will expand to poll tokenList across each network added to any given wallet. This will result in a larger dataset for the to consume.

This PR branches off of multiexchangerate branch because it will incorporate the useMultiPolling hook needed to initialize polling loops across chainIds.

For each chain imported into the wallet, we should start a new polling loop and update tokensChainsCache. We also want to update tokenList for the selected chain (this should eventually be deprecated)

This should now be working to test locally. Here's some steps to run this locally with core PR:

  1. Ensure you are running this corresponding core PR branch locally
  2. Link resolution of assets-controllers in package.json: "@metamask/assets-controllers": "../core/packages/assets-controllers",
  3. Assign result of useTokenListPolling hook in TokenListProvider to a variable and log it:
const tokenListPoll = useTokenListPolling();
console.log('tokenListPoll', tokenListPoll);
  1. In core, modify the DEFAULT_INTERVAL to 3 seconds: const DEFAULT_INTERVAL = 3 * 1000;

Build core, install on extension, and run extension.

Open in GitHub Codespaces

Related issues

Fixes: https://github.com/MetaMask/MetaMask-planning/issues/3429

Manual testing steps

  1. Ensure that tokensChainsCache polls imported chainIds (one poll per network)
  2. Ensure that tokenList gets updated with metadata for the current chain only

Screenshots/Recordings

Screen.Recording.2024-10-31.at.3.45.27.PM.mov

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

bergeron and others added 30 commits October 22, 2024 14:30
…ask-extension into brian/asset-controller-39
…MetaMask/metamask-extension into brian/multiexchangerate
@gambinish gambinish changed the base branch from brian/multiexchangerate to develop November 1, 2024 19:52
@gambinish gambinish changed the title 3429 tokenlist controller polling feat: Integrate new TokenListController polling pattern [Extension] Nov 1, 2024
@gambinish
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

gambinish added a commit to MetaMask/core that referenced this pull request Nov 5, 2024
## Explanation

_TokenListController is currently responsible for maintaining a list of
all tokens per chain. This dataset is accessible via `tokenList` state
variable in metamask state. After this task is complete, this token list
will migrate it's polling pattern to leverage the base class, to execute
a single poll per chain, rather than on an interval for all chains_
___

Move `TokenListController` away from being scoped to a single polling
loop, to executing individual polling loops per chain, allowing it to be
more UI based in its controls.

The controller will accept `PollingInputs` from the extension from
various UI elements, and will be responsible for starting, stopping, and
deduping polls as needed. Deduping is baked into the inherited base
class `StaticIntervalPollingController`

Here is the corresponding [PR in
extension](MetaMask/metamask-extension#28198)
that consumes and integrates with this controller. There will also be an
additional mobile PR at some point to implement something similar.

## References

MetaMask/MetaMask-planning#3429

## Changelog

<!--
If you're making any consumer-facing changes, list those changes here as
if you were updating a changelog, using the template below as a guide.

(CATEGORY is one of BREAKING, ADDED, CHANGED, DEPRECATED, REMOVED, or
FIXED. For security-related issues, follow the Security Advisory
process.)

Please take care to name the exact pieces of the API you've added or
changed (e.g. types, interfaces, functions, or methods).

If there are any breaking changes, make sure to offer a solution for
consumers to follow once they upgrade to the changes.

Finally, if you're only making changes to development scripts or tests,
you may replace the template below with "None".
-->

### `@metamask/package-a`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: Your change here

### `@metamask/package-b`

- **<CATEGORY>**: Your change here
- **<CATEGORY>**: Your change here

## Checklist

- [ ] I've updated the test suite for new or updated code as appropriate
- [ ] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [ ] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
- [ ] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes
@gambinish
Copy link
Contributor Author

closing in favor of: #28447

@gambinish gambinish closed this Nov 18, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Nov 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants